package com.dly.hope.controller;

import com.dly.hope.annotation.LoginRole;
import com.dly.hope.constant.R;
import com.dly.hope.vo.RoleShow;
import com.dly.hope.model.vo.UserShow;
import com.dly.hope.pageUtils.PageRo;
import com.dly.hope.service.RoleService;
import com.dly.hope.service.UserAccountService;
import com.dly.hope.type.RoleType;
import com.dly.hope.pageUtils.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@Api(tags = "后台相关接口")
@RequestMapping(value = "/end")
public class EndController extends BaseController{

    @Resource
    private UserAccountService userAccountService;

    @Resource
    private RoleService roleService;

    @ApiOperation(value = "让用户失效/启用")
    @PostMapping("/delete")
    @LoginRole(role = RoleType.SUPER_ADMIN)
    public ResponseEntity<R<Void>> deleteUser(@RequestBody Map<String,List<String>> map){
        userAccountService.deleteUser(map.get("userIds"));
        return operate(this::success);
    }

    @ApiOperation(value = "强制退出")
    @PostMapping("/forcedExit")
    @LoginRole(role = RoleType.SUPER_ADMIN)
    public ResponseEntity<R<Void>> forcedExit(@RequestBody Map<String,List<String>> map){
        userAccountService.forcedExit(map.get("userIds"));
        return operate(this::success);
    }

    @ApiOperation(value = "所有的用户信息")
    @GetMapping("/getAll")
    @LoginRole(role = RoleType.SUPER_ADMIN)
    public ResponseEntity<R<Page<UserShow>>> getAllUserAccount(PageRo pageRo){
        return operate(()-> this.successDate(userAccountService.getAll(pageRo)));
    }

    @ApiOperation(value = "获取所有角色信息")
    @GetMapping("/getAllRole")
    @LoginRole(role = RoleType.SUPER_ADMIN)
    public ResponseEntity<R<Page<RoleShow>>> getAllRole(PageRo pageRo){
        return operate(()-> this.successDate(roleService.getAll(pageRo)));
    }
}
